import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Breadcrumb, Row, Col, Input, Tabs,Button,Steps,message,Card } from 'antd';
import './AddFormDetail.scss';
import API from '../../../../api/files/index';
import FirstContent from '../FirstContent/FirstContent';
import SecondContent from '../SecondContent/SecondContent';
import ThirdContent from '../ThirdContent/ThirdContent';
const Step = Steps.Step;
class FormDetail extends Component {

    constructor (props) {
        super(props);
        this.state = {
             current: 0,
             value: 1,
             id:'',
             firstContent:{},
        };
       }

  next=async(e)=> {
    console.log(this.state.current);
    if(this.state.current == 0){
          const param= await this.child.handleSaveContent(e);
          const current = this.state.current + 1;
          this.setState({
            current,
            id:param.data,
            firstContent:param.params,
          });
    }else if(this.state.current == 1){
      const param = await this.child.handleUploadFile();
      const param1 = await this.child.handleUploadFile1();
      const param2 = await this.child.handleUploadFile2();
      const param3 = await this.child.handleUploadFile3();
      const param4 = await this.child.handleUploadFile4();
        const id = this.state.id;
        const firstContent = this.state.firstContent;
        var params = firstContent;
        params.id = id;
        if(param !== undefined){
          params.licenses = [];
          params.licenses.push(param);
        }
        if(param1 !== undefined){
          params.licenses = [];
          params.licenses.push(param1);
        }
        if(param2 !== undefined){
          params.licenses = [];
          params.licenses.push(param2);
        }
        if(param3 !== undefined){
          params.licenses = [];
          params.licenses.push(param3);
        }
        if(param4 !== undefined){
          params.agreements = [];
          params.agreements.push(param4);
        }
        const response = await API.addManage(params);
        const { code, data } = response;
        if (code === 1) {
          message.success('添加成功');
          const current = this.state.current + 1;
          this.setState({
            current,
          });
        }
    }

  }

  prev() {
    const current = this.state.current - 1;
    this.setState({ current });
  }

  onRef = (ref) => {
    this.child = ref
}

 onSuccess=()=>{
   console.log(listData);
 }
    render () {
        var screenHeight = document.body.clientHeight;
        const { current } = this.state;
        const steps = [{
            title: '基本信息',
            content: <FirstContent  onRef={this.onRef} tabIndex={this.props.tabIndex}/>,
          }, {
            title: '工商文件',
            content: <SecondContent  onRef={this.onRef}  tabIndex={this.props.tabIndex}/>,
          }, {
            title: '股东信息',
            content: <ThirdContent  onRef={this.onRef}  tabIndex={this.props.tabIndex}/>,
          }];

        return (
        <div className="formDetailShow">
         <div className="flow">
        <Steps className="antStep" current={current}>
          {steps.map(item => <Step key={item.title} title={item.title} />)}
        </Steps>
        <div className="steps-content">{steps[this.state.current].content}</div>

        <div className="steps-action">
          {
            this.state.current < steps.length - 1
            &&
            <Button type="primary" onClick={e => this.next(e)} style={{background:'#1890ff'}}>保存并下一步</Button>
          }
          {
            this.state.current === steps.length - 1
            &&
            <Button type="primary" style={{background:'#1890ff'}} onClick={this.onSuccess}>完成</Button>
          }
          {
            this.state.current > 0
            &&
            <Button style={{ marginLeft: 8 }} onClick={() => this.prev()}>
              上一步
            </Button>
          }
        </div>
      </div>
     </div>
          );
    }
}

export default FormDetail;